package com.zhugang.week11;

/**
 * @program algorithms
 * @description: climbStairs2
 * @author: chanzhugang
 * @create: 2022/09/01 21:06
 */
public class ClimbStairs2 {

    /**
     * 70 爬楼梯
     *
     * @param n
     * @return
     */
    public int climbStairs2(int n) {
        // 有多少种爬法：dp计数问题
        // int[i] dp = dp[i - 1] + dp[i - 2]
        if (n <= 2) {
            return n;
        }
        int[] dp = new int[n + 1];
        dp[1] = 1;
        dp[2] = 2;
        for (int i = 3; i <= n; i++) {
            dp[i] = dp[i - 1] + dp[i - 2];
        }
        return dp[n];
    }
}